home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!xs4all!usenet
- From: martijnl@xs4all.nl (Martijn Lievaart)
- Newsgroups: comp.lang.c++
- Subject: Re: Unable to use 'delete' after 'new'
- Date: Sun, 24 Mar 1996 11:03:44 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4j3a71$n10@news.xs4all.nl>
- References: <4iursi$ibc@lisa.iosphere.net>
- NNTP-Posting-Host: mas01-09.dial.xs4all.nl
- X-Newsreader: Forte Free Agent 1.0.82
-
- ianq@sonetis.com (Ian V. Quickmire) wrote:
-
- (snip)
- >I tried the basic delete [] iColsize from the calling function, and got a
- >memory exception.
- (snip)
- >Up until I do the SQLFetch, I can do a 'delete [] sPassStr' fine.
- >After the Fetch is executed, if I do a delete, I get a memory exception.
-
- >Any ideas?
-
- I'ld say the problem is not in new/delete. I think you're suffering
- from a bug somewhere else in your program that overwrites memory where
- it is not supposed to.
- Somehow the pointer gets corrupted and when freeing this corrupted
- pointer, Windows (quite rightly) complains. I would use a debugger or
- messageboxes to trace the program and see what pointer new returned,
- what pointer you're deleting, and where it gets corrupted.
-
- How can this happen? Probably array overrun. This is the most common
- cause. Take f.i.
- char buf[8];
- strcpy(buf, "12345678");
- This will write 1 byte to many (the terminating '\0').
-
- C++ makes it very easy to shoot yourself in the foot in a zillion
- ways, there are indeed a zillion ways to corrupt a pointer. My advice:
- use a debugger, investigate, have a flash of insight, never make that
- mistake again. Works better than when someone points out the bug.
-
- On the other hand, it might be something else, though I would bet on
- pointer corruption.
-
- Hope this helps,
- Martijn.
-
- BTW, see if your debugger supports the 386-hardware breakpoints, they
- can speed up this kind of debugging. Set a hardware breakpoint on the
- location contianing the pointer (not where the pointer points to but
- where the pointer itself is stored) and the debugger will break at the
- statement that corrupts the pointer.
-
- /~~~~~| /~~~~~| /~~~~~~|~~~~~\~~~~~\~~~~|~~~~~| We now return to our
- / |/ |/ | o | o | | +-| regularly scheduled
- / /| /| | /| | ___/ ___/ | +-| flame-throwing
- ../___/.|____/.|___|__/~|___|_|..|__|..|_____|_____|...martijnl@xs4all.nl..
-
-